Skip to content

perf: integrate batched Keccacheck receipt circuit - #2

Closed
ozwaldorf wants to merge 22 commits into
mainfrom
opt/keccacheck-arkworks-integration
Closed

ozwaldorf wants to merge 22 commits into
mainfrom
opt/keccacheck-arkworks-integration

Conversation

@ozwaldorf

Copy link
Copy Markdown
Member

Summary

  • carries the complete universal depth-seven constructed-leaf optimization stack
  • replaces direct Keccak-f constraints with one private 64-way Keccacheck GKR batch
  • keeps the GKR proof private inside one externally verified Groth16 proof
  • adds experimental setup/prove APIs and an end-to-end measurement mode

Current measurement

On an Intel Core i9-14900HX with 16 Rayon threads:

  • 4,034,927 constraints, down from 8,095,727
  • 24.9 seconds Groth16 proving, including native GKR witness generation
  • 28.8 seconds one-time circuit-specific setup
  • 12.6 GiB peak process RSS across diagnostic synthesis, setup, and proving
  • 128-byte compressed Groth16 proof and two public statement limbs

This is a single host sample, not an SGX measurement or latency distribution.

Validation

  • complete genuine relation is satisfied with 38 real permutations padded to 64
  • native GKR proof satisfies the full in-circuit 24-round verifier
  • mutated GKR proof/output and incorrect authenticated header hash are rejected
  • generated Groth16 proof verifies; a mutated public statement is rejected

Before merge

  • audit transcript domain separation and output-derived challenge adaptation
  • vendor or migrate the pinned upstream GKR prover and remove the arkworks 0.5/0.6 conversion
  • make the GKR dependency compatible with the Fortanix SGX target
  • run full mutation/mainnet fixture coverage
  • measure proof latency and proving-only peak memory on target SGX hardware

Stacked E2E escrow and Nomad draft PRs will be linked here.

A node must not derive its own key: circuit_specific_setup leaves one party
able to forge any statement, which spec 18.2's multiparty Phase 2 exists to
prevent. load_proving_key reads a ceremony's output instead, kept as a separate
function so the unsound path cannot be reached by omitting an argument, and
validating point encodings once at load rather than trusting them per proof.

verifying_key_constants derives the flat field elements the generated Solidity
verifier compiles in. A node holds only the proving half but the escrow embeds
the verifying half, so this lets it confirm the two came from the same setup
before proving rather than discovering the mismatch as a rejected proof after
fronting a transfer. A test pins the derivation against contracts/Verifier.sol.

Tests share one key: setup is ~8.7 GiB, and four of them in parallel exhausted
memory before reaching an assertion.
The statement carried a 180-block lease and a witness 100 blocks after
bonding. EscrowBase sets executionDeadline = block.number + 25, so no
caller that bonded through the contract could ever hold that state: the
proof was only spendable by forging bond storage directly.

Narrows the lease to 25 blocks and moves the witness inside it, so a
fund/bond/collect chain reproduces the statement. The header's encoded
number moves with it, since the relation binds the two.

Regenerates proof.json and calldata.txt. Verifier.sol is unchanged: the
constraint system did not move, only the witness.
The statement committed to 0x22..22, which no deployment produces. A
consumer could only get the contract there by relocating it after
construction, and that breaks bond(): the escrow caches its EIP-712
domain separator over address(this) at construction, so a moved copy
rejects every signature written against its new address.

Uses the address a CREATE from 0x01..01 at nonce 0 yields, so the escrow
can be deployed where the proof expects it and the whole fund/bond/
collect chain runs. The intent commitment moves with it, since spec 8.3
binds the escrow.
load_proving_key had no inverse, so a caller that generated a key could
not persist it. save_proving_key mirrors it, sharing the compressed flag
the two must agree on, and serialize_verifying_key exposes the canonical
bytes that identify a setup: hashing them gives a caller a fingerprint to
check an untrusted proving key against without reproducing the setup.

The key types are aliased so a consumer can name what Keys holds without
depending on the arkworks crates directly.
@ozwaldorf

Copy link
Copy Markdown
Member Author

Stacked E2E integration:

The full mocked-enclave Anvil flow passes. Actual SGX timing remains the hardware gate because the development host has no SGX device or active AESM.

The all-zero selector is how `one_hot` encodes an out-of-range index, so it
is satisfiable for an in-range index too. A prover supplying it suppresses a
byte or nibble read, which then returns zero and satisfies any equality
against it. Range-constraining the index does not help: the suppressed read
is at an in-range index.

Add `one_hot_in_range` and `nibble_at_with`, which keep the definitional
constraints ungated and add a gated assertion that a hit occurred. Gate the
reads whose zero would otherwise satisfy something: branch child selection,
the traversal nibbles, the hex-prefix flag byte, both sides of the path
match, and the constructed leaf path. Speculative reads still pass a false
active.

Also bound `receipt_len` by the receipt buffer in the leaf gadget and
`key_len` by the key buffer in the traversal, so neither depends on a
sibling module for the extent it hashes, and pin `asset_kind` to ERC-20 in
the relation rather than resting on address(0) being unable to emit logs.

Costs 1,456 constraints: 8,095,727 to 8,097,183 direct, 4,034,927 to
4,036,383 batched.
The batched circuit is the one that would ship but only ran two mutation
cases, so a deferral that dropped a binding rather than only its cost would
not have been caught. Run the direct circuit's mutations through it as well.

A one-permutation batch is a distinct path: log_instances is zero, the first
sumcheck runs zero rounds, and the output claim reduces to a linear
combination of the claimed output words. Since padded is a power of two, any
caller doing a single permutation reaches it. Cover both directions.

Extend the second-event rejection to Erc20FixedLayout, which is the variant
the relation wires; only Erc20SingleLog was covered.

Record the open security items in RESULTS.md: the receipt-identity gap is
carried by an out-of-circuit nomad invariant, and the Poseidon-derived output
challenge and absent transcript domain separation still need cryptographic
sign-off. Update the constraint counts for b5192b4.
@ozwaldorf ozwaldorf closed this Oct 8, 2026
@ozwaldorf
ozwaldorf deleted the opt/keccacheck-arkworks-integration branch October 19, 2026 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant